# file: multicore_test09.py
import machine
import _thread
import utime
from ws2812 import WS2812

led = machine.Pin(25, machine.Pin.OUT)
led.off()

BLACK = (0, 0, 0)
RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)
WHITE = (255, 255, 255)
COLORS = (BLACK, RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE)

ws = WS2812(3, 1) #WS2812(pin_num,led_count)
ws.pixels_fill(BLACK)
ws.pixels_show()

def run_on_core1():
    while True:
        for color in COLORS:
            ws.pixels_fill(color)
            ws.pixels_show()
            utime.sleep_ms(200)

def run_on_core0():
    duty = 0
    step = 1
    count = 0
    while True:
        led.on()
        utime.sleep_ms(duty)
        led.off()
        utime.sleep_ms(10-duty)

        count = count + 1
        if count>10:
            count = 0
            duty = duty + step
            if duty >= 10:
                step = -1
            if duty <= 0 :
                step = 1

_thread.start_new_thread(run_on_core1, ( ))
run_on_core0()